// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.QueryDsl;

public sealed partial class IntervalsMatch
{
	/// <summary>
	/// <para>
	/// Analyzer used to analyze terms in the query.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("analyzer")]
	public string? Analyzer { get; set; }

	/// <summary>
	/// <para>
	/// An optional interval filter.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("filter")]
	public Elastic.Clients.Elasticsearch.QueryDsl.IntervalsFilter? Filter { get; set; }

	/// <summary>
	/// <para>
	/// Maximum number of positions between the matching terms.
	/// Terms further apart than this are not considered matches.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("max_gaps")]
	public int? MaxGaps { get; set; }

	/// <summary>
	/// <para>
	/// If <c>true</c>, matching terms must appear in their specified order.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("ordered")]
	public bool? Ordered { get; set; }

	/// <summary>
	/// <para>
	/// Text you wish to find in the provided field.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("query")]
	public string Query { get; set; }

	/// <summary>
	/// <para>
	/// If specified, match intervals from this field rather than the top-level field.
	/// The <c>term</c> is normalized using the search analyzer from this field, unless <c>analyzer</c> is specified separately.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("use_field")]
	public Elastic.Clients.Elasticsearch.Field? UseField { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.QueryDsl.Intervals(IntervalsMatch intervalsMatch) => Elastic.Clients.Elasticsearch.QueryDsl.Intervals.Match(intervalsMatch);
	public static implicit operator Elastic.Clients.Elasticsearch.QueryDsl.IntervalsQuery(IntervalsMatch intervalsMatch) => Elastic.Clients.Elasticsearch.QueryDsl.IntervalsQuery.Match(intervalsMatch);
}

public sealed partial class IntervalsMatchDescriptor<TDocument> : SerializableDescriptor<IntervalsMatchDescriptor<TDocument>>
{
	internal IntervalsMatchDescriptor(Action<IntervalsMatchDescriptor<TDocument>> configure) => configure.Invoke(this);

	public IntervalsMatchDescriptor() : base()
	{
	}

	private string? AnalyzerValue { get; set; }
	private Elastic.Clients.Elasticsearch.QueryDsl.IntervalsFilter? FilterValue { get; set; }
	private Elastic.Clients.Elasticsearch.QueryDsl.IntervalsFilterDescriptor<TDocument> FilterDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.QueryDsl.IntervalsFilterDescriptor<TDocument>> FilterDescriptorAction { get; set; }
	private int? MaxGapsValue { get; set; }
	private bool? OrderedValue { get; set; }
	private string QueryValue { get; set; }
	private Elastic.Clients.Elasticsearch.Field? UseFieldValue { get; set; }

	/// <summary>
	/// <para>
	/// Analyzer used to analyze terms in the query.
	/// </para>
	/// </summary>
	public IntervalsMatchDescriptor<TDocument> Analyzer(string? analyzer)
	{
		AnalyzerValue = analyzer;
		return Self;
	}

	/// <summary>
	/// <para>
	/// An optional interval filter.
	/// </para>
	/// </summary>
	public IntervalsMatchDescriptor<TDocument> Filter(Elastic.Clients.Elasticsearch.QueryDsl.IntervalsFilter? filter)
	{
		FilterDescriptor = null;
		FilterDescriptorAction = null;
		FilterValue = filter;
		return Self;
	}

	public IntervalsMatchDescriptor<TDocument> Filter(Elastic.Clients.Elasticsearch.QueryDsl.IntervalsFilterDescriptor<TDocument> descriptor)
	{
		FilterValue = null;
		FilterDescriptorAction = null;
		FilterDescriptor = descriptor;
		return Self;
	}

	public IntervalsMatchDescriptor<TDocument> Filter(Action<Elastic.Clients.Elasticsearch.QueryDsl.IntervalsFilterDescriptor<TDocument>> configure)
	{
		FilterValue = null;
		FilterDescriptor = null;
		FilterDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Maximum number of positions between the matching terms.
	/// Terms further apart than this are not considered matches.
	/// </para>
	/// </summary>
	public IntervalsMatchDescriptor<TDocument> MaxGaps(int? maxGaps)
	{
		MaxGapsValue = maxGaps;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If <c>true</c>, matching terms must appear in their specified order.
	/// </para>
	/// </summary>
	public IntervalsMatchDescriptor<TDocument> Ordered(bool? ordered = true)
	{
		OrderedValue = ordered;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Text you wish to find in the provided field.
	/// </para>
	/// </summary>
	public IntervalsMatchDescriptor<TDocument> Query(string query)
	{
		QueryValue = query;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If specified, match intervals from this field rather than the top-level field.
	/// The <c>term</c> is normalized using the search analyzer from this field, unless <c>analyzer</c> is specified separately.
	/// </para>
	/// </summary>
	public IntervalsMatchDescriptor<TDocument> UseField(Elastic.Clients.Elasticsearch.Field? useField)
	{
		UseFieldValue = useField;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If specified, match intervals from this field rather than the top-level field.
	/// The <c>term</c> is normalized using the search analyzer from this field, unless <c>analyzer</c> is specified separately.
	/// </para>
	/// </summary>
	public IntervalsMatchDescriptor<TDocument> UseField<TValue>(Expression<Func<TDocument, TValue>> useField)
	{
		UseFieldValue = useField;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If specified, match intervals from this field rather than the top-level field.
	/// The <c>term</c> is normalized using the search analyzer from this field, unless <c>analyzer</c> is specified separately.
	/// </para>
	/// </summary>
	public IntervalsMatchDescriptor<TDocument> UseField(Expression<Func<TDocument, object>> useField)
	{
		UseFieldValue = useField;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (!string.IsNullOrEmpty(AnalyzerValue))
		{
			writer.WritePropertyName("analyzer");
			writer.WriteStringValue(AnalyzerValue);
		}

		if (FilterDescriptor is not null)
		{
			writer.WritePropertyName("filter");
			JsonSerializer.Serialize(writer, FilterDescriptor, options);
		}
		else if (FilterDescriptorAction is not null)
		{
			writer.WritePropertyName("filter");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.QueryDsl.IntervalsFilterDescriptor<TDocument>(FilterDescriptorAction), options);
		}
		else if (FilterValue is not null)
		{
			writer.WritePropertyName("filter");
			JsonSerializer.Serialize(writer, FilterValue, options);
		}

		if (MaxGapsValue.HasValue)
		{
			writer.WritePropertyName("max_gaps");
			writer.WriteNumberValue(MaxGapsValue.Value);
		}

		if (OrderedValue.HasValue)
		{
			writer.WritePropertyName("ordered");
			writer.WriteBooleanValue(OrderedValue.Value);
		}

		writer.WritePropertyName("query");
		writer.WriteStringValue(QueryValue);
		if (UseFieldValue is not null)
		{
			writer.WritePropertyName("use_field");
			JsonSerializer.Serialize(writer, UseFieldValue, options);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class IntervalsMatchDescriptor : SerializableDescriptor<IntervalsMatchDescriptor>
{
	internal IntervalsMatchDescriptor(Action<IntervalsMatchDescriptor> configure) => configure.Invoke(this);

	public IntervalsMatchDescriptor() : base()
	{
	}

	private string? AnalyzerValue { get; set; }
	private Elastic.Clients.Elasticsearch.QueryDsl.IntervalsFilter? FilterValue { get; set; }
	private Elastic.Clients.Elasticsearch.QueryDsl.IntervalsFilterDescriptor FilterDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.QueryDsl.IntervalsFilterDescriptor> FilterDescriptorAction { get; set; }
	private int? MaxGapsValue { get; set; }
	private bool? OrderedValue { get; set; }
	private string QueryValue { get; set; }
	private Elastic.Clients.Elasticsearch.Field? UseFieldValue { get; set; }

	/// <summary>
	/// <para>
	/// Analyzer used to analyze terms in the query.
	/// </para>
	/// </summary>
	public IntervalsMatchDescriptor Analyzer(string? analyzer)
	{
		AnalyzerValue = analyzer;
		return Self;
	}

	/// <summary>
	/// <para>
	/// An optional interval filter.
	/// </para>
	/// </summary>
	public IntervalsMatchDescriptor Filter(Elastic.Clients.Elasticsearch.QueryDsl.IntervalsFilter? filter)
	{
		FilterDescriptor = null;
		FilterDescriptorAction = null;
		FilterValue = filter;
		return Self;
	}

	public IntervalsMatchDescriptor Filter(Elastic.Clients.Elasticsearch.QueryDsl.IntervalsFilterDescriptor descriptor)
	{
		FilterValue = null;
		FilterDescriptorAction = null;
		FilterDescriptor = descriptor;
		return Self;
	}

	public IntervalsMatchDescriptor Filter(Action<Elastic.Clients.Elasticsearch.QueryDsl.IntervalsFilterDescriptor> configure)
	{
		FilterValue = null;
		FilterDescriptor = null;
		FilterDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Maximum number of positions between the matching terms.
	/// Terms further apart than this are not considered matches.
	/// </para>
	/// </summary>
	public IntervalsMatchDescriptor MaxGaps(int? maxGaps)
	{
		MaxGapsValue = maxGaps;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If <c>true</c>, matching terms must appear in their specified order.
	/// </para>
	/// </summary>
	public IntervalsMatchDescriptor Ordered(bool? ordered = true)
	{
		OrderedValue = ordered;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Text you wish to find in the provided field.
	/// </para>
	/// </summary>
	public IntervalsMatchDescriptor Query(string query)
	{
		QueryValue = query;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If specified, match intervals from this field rather than the top-level field.
	/// The <c>term</c> is normalized using the search analyzer from this field, unless <c>analyzer</c> is specified separately.
	/// </para>
	/// </summary>
	public IntervalsMatchDescriptor UseField(Elastic.Clients.Elasticsearch.Field? useField)
	{
		UseFieldValue = useField;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If specified, match intervals from this field rather than the top-level field.
	/// The <c>term</c> is normalized using the search analyzer from this field, unless <c>analyzer</c> is specified separately.
	/// </para>
	/// </summary>
	public IntervalsMatchDescriptor UseField<TDocument, TValue>(Expression<Func<TDocument, TValue>> useField)
	{
		UseFieldValue = useField;
		return Self;
	}

	/// <summary>
	/// <para>
	/// If specified, match intervals from this field rather than the top-level field.
	/// The <c>term</c> is normalized using the search analyzer from this field, unless <c>analyzer</c> is specified separately.
	/// </para>
	/// </summary>
	public IntervalsMatchDescriptor UseField<TDocument>(Expression<Func<TDocument, object>> useField)
	{
		UseFieldValue = useField;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (!string.IsNullOrEmpty(AnalyzerValue))
		{
			writer.WritePropertyName("analyzer");
			writer.WriteStringValue(AnalyzerValue);
		}

		if (FilterDescriptor is not null)
		{
			writer.WritePropertyName("filter");
			JsonSerializer.Serialize(writer, FilterDescriptor, options);
		}
		else if (FilterDescriptorAction is not null)
		{
			writer.WritePropertyName("filter");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.QueryDsl.IntervalsFilterDescriptor(FilterDescriptorAction), options);
		}
		else if (FilterValue is not null)
		{
			writer.WritePropertyName("filter");
			JsonSerializer.Serialize(writer, FilterValue, options);
		}

		if (MaxGapsValue.HasValue)
		{
			writer.WritePropertyName("max_gaps");
			writer.WriteNumberValue(MaxGapsValue.Value);
		}

		if (OrderedValue.HasValue)
		{
			writer.WritePropertyName("ordered");
			writer.WriteBooleanValue(OrderedValue.Value);
		}

		writer.WritePropertyName("query");
		writer.WriteStringValue(QueryValue);
		if (UseFieldValue is not null)
		{
			writer.WritePropertyName("use_field");
			JsonSerializer.Serialize(writer, UseFieldValue, options);
		}

		writer.WriteEndObject();
	}
}